<?php

    function GetTree($arr,$pid,$step){
        global $tree;
        foreach($arr as $key=>$val) {
            if($val['parent_id'] == $pid) {
                $flg = str_repeat('└―',$step);
                $val['name'] = $flg.$val['name'];
                $tree[] = $val;
                GetTree($arr , $val['id'] ,$step+1);
            }
        }

        return $tree;
    }

    function inarray($id,$arr){
        $idarr = array_column($arr->toArray(), 'sku_id');
            if(in_array($id, $idarr)){
                return true;
            }
        
        return false;
    }

    function getstr($id,$arr){
        foreach ($arr as $k => $v) {
            if($v->sku_id==$id){
                $str=$v->sku_id."|".$v->sku."|".$v->package_itemid."|".$v->number;
                return $str;
            }
        }
        return false;
    }

    function get_package_itemid($id,$arr){
        foreach ($arr as $k => $v) {
            if($v->sku_id==$id){
                $str=$v->package_itemid;
                return $str;
            }
        }
        return false;
    }

    function get_number($id,$arr){
        foreach ($arr as $k => $v) {
            if($v->sku_id==$id){
                $str=$v->number;
                return $str;
            }
        }
        return false;
    }


function in_permission($id,$arr){
    foreach ($arr as $k => $v) {
        if($v->id==$id){
            return true;
        }
    }
    return false;
}

function make_tree($list,$pk='id',$cid='cid',$child='_child',$root=0){  
    $tree=array();   
    $packData=array();  
    foreach ($list as  $data) {  
        $packData[$data[$pk]] = $data; //$packData[1]=$data; $packData[2]=$data   
    }  
    foreach ($packData as $key =>$val){       
        if($val[$cid]==$root){   //代表跟节点         
            $tree[]=& $packData[$key];  
        }else{  
            //找到其父类  
            $packData[$val[$cid]][$child][]=& $packData[$key];  
        }  
    }  
    return $tree;  
}  
function in($urlPath,$arr){
        if(isset($arr['_child'])){
            foreach ($arr['_child'] as $k => $v) {
                if($v['name']==$urlPath){
                    return true;
                }elseif(isset($v['_child'])){

                    $this->in($urlPath,$v['_child']);
                }
            }
            return false;
        }
    }
